package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Order;
import com.itheima.reggie.service.OrderService;
import com.sun.xml.bind.v2.model.core.ID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zsk
 * @create 2022-02-19-20:32
 */
@RestController
public class OrderController {

    //依赖注入
    @Autowired
    private OrderService orderService;

    /*
    点击支付
    Request URL: http://localhost:8081/order/submit
    Request Method: POST
     */
    @PostMapping("/order/submit")
    public ResultInfo submit(@RequestBody Order order){

        //调用service层保存
        orderService.save(order);

        //返回结果
        return ResultInfo.success(null);

    }

    /*
    查询历史订单
    Request URL: http://localhost:8081/order/userPage?page=1&pageSize=5
    Request Method: GET
     */
    @GetMapping("/order/userPage")
    public ResultInfo findByPage(@RequestParam(value = "page",defaultValue = "1") Integer pageNum,//代表当前页数，
                                 @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize//代表一页多少条数据
    ){
        //调用service层查询
        Page<Order> page = orderService.findByPage(pageNum,pageSize);

        //返回结果
        return ResultInfo.success(page);

    }


}
